const demo = require("../models/demo.js");
const express = require("express");

var router = express.Router();

const formidable = require('formidable');

//返回图片
router.post('/', (req, res, next) => {
    var form = new formidable.IncomingForm();
    form.parse(req, function (err, fields, files) {
        if (err) {
            res.json({ 'state': false })
        } else {
          console.log()
          demo.findByIdAndUpdate(fields.id, {
            description: fields.description,
            js_content: fields.js,
            html_content: fields.html,
            css_content: fields.css,
          }, (error, doc) => {
                if (error) {
                    res.json({ 'state': false, 'msg': error });
                } else {
                    res.json({
                        'state': true,
                        'msg': '更新成功！' 
                    })
                }
            })

        }

    });

});

module.exports = router;